# This is a sample Python script.
import os
import time

import common

# 针对选定的文件增加注释
if __name__ == '__main__':
    file_list = common.open_multi_file_win('选择文件')
    # 读取注释模板文件
    file_map = common.get_template_map(os.getcwd() + os.sep + 'template', [])
    start_time = int(time.time())
    for index, file_name in enumerate(file_list):
        plitext = os.path.splitext(file_name)
        # 获取文件类型，读取模板文件
        with open(file_map.get(plitext[1]), encoding='utf-8') as template_file:
            file_read = template_file.read()
        count = len(open(file_name, encoding='utf-8').readlines())
        num = count / 200 + 1
        # 根据比率增加
        with open(file_name, 'a+', encoding='utf-8') as f:
            f.write('\n')
            for ind in range(0, int(num)):
                f.write(file_read + '\n')
    end_time = int(time.time())
    print('总用时：%i' % (end_time - start_time))
